import requests

s = requests.Session()

host = 'http://localhost'
# 登陆
url = host + '/smeoa/index.php?m=login&a=check_login'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
datas = {'emp_no': 'admin', 'password': 'admin'}
r = s.post(url, data=datas)
if '退出' in r.text:
    print('登陆成功')
else:
    print('登陆失败')

# 添加附件接口, 响应中的sid做为参数传入新增日报的请求正文中
url = host + '/smeoa/task/upload'
datas = {'name': 'addreport.txt'}
files = {'file': open('addreport.txt', 'rb')}
r = s.post(url, data=datas, files=files)
sid = r.json()['sid']
print(sid)

# 添加带附件的日报. 附件添加成功
datas = {'executor': '总监2001|42', 'opmode': 'add', 'name': '1120-1335', 'expected_time': '2023-12-01 15:10',
         'content': 'content', 'add_file': sid}
r = s.post(host + '/smeoa/index.php?m=task&a=save', data=datas)
if '新增成功' in r.text:
    print('新增成功')
else:
    print('新增失败')
